package com.airport.schedule;

public class ScheduleEvaluator {

    public static double evaluateForGenetic(ScheduleSolution solution) {
        int hardConflict = solution.getFlightGateConflictNum();
        int runwayConflict = solution.getRunwayConflictNum();
        int nearGateFlight = solution.getNearGateFlightNum();
        int adHocFlightNum = solution.getAdHocFlightNum();
        return 1.5 * hardConflict + 1.2 * (solution.getScheduledFlightNum()-nearGateFlight)
                + 1.1 * runwayConflict + adHocFlightNum;
    }

    public static double evaluateForGenetic1(ScheduleSolution solution,
                                             double c1, double c2, double c3, double c4) {
        int hardConflict = solution.getFlightGateConflictNum();
        int runwayConflict = solution.getRunwayConflictNum();
        int nearGateFlight = solution.getNearGateFlightNum();
        int adHocFlightNum = solution.getAdHocFlightNum();
        return c1 * hardConflict + c2 * (solution.getScheduledFlightNum()-nearGateFlight)
                + c3 * runwayConflict + c4 * adHocFlightNum;
    }

    public static double geneticScore(ScheduleSolution solution, int totalFlights, int totalPeople) {
        int runwayConflict = solution.getRunwayConflictNum();
        int nearGateFlight = solution.getNearGateFlightNum();
        int nearGatePeople = solution.getNearGatePeopleNum();
        int adHocFlightNum = solution.getAdHocFlightNum();
        int scheduledFlight = solution.getScheduledFlightNum();
        int hardConflict = solution.getFlightGateConflictNum();
        return (10.0 * scheduledFlight + 3.0 * nearGateFlight - adHocFlightNum - runwayConflict)
                / totalFlights + (3.0 * nearGatePeople)/totalPeople - 10 * hardConflict;
    }

    // 最终得分计算
    public static double getScore(ScheduleSolution solution, int totalFlights, int totalPeople) {
        int runwayConflict = solution.getRunwayConflictNum();
        int nearGateFlight = solution.getNearGateFlightNum();
        int nearGatePeople = solution.getNearGatePeopleNum();
        int adHocFlightNum = solution.getAdHocFlightNum();
        int scheduledFlight = solution.getScheduledFlightNum();
        return (10.0 * scheduledFlight + 3.0 * nearGateFlight - adHocFlightNum - runwayConflict)
                / totalFlights + (3.0 * nearGatePeople)/totalPeople;
    }

    public static String describe(ScheduleSolution solution, int totalFlights, int totalPeople) {
        return "需要调度的飞机数量: "+totalFlights+"\n" +
                "需要调度的旅客数量: "+totalPeople+"\n"+
                "实际参与调度的航班数量: "+solution.getInvolvedFlightNum()+"\n"+
                "安排到机位的航班数量: "+solution.getScheduledFlightNum()+"\n" +
                "没有机位的航班数: "+(totalFlights-solution.getScheduledFlightNum())+"\n"+
                "采用了临时措施的航班数量: "+solution.getAdHocFlightNum()+"\n"+
                "滑道冲突数量: "+solution.getRunwayConflictNum()+"\n"+
                "近机位航班数量: "+solution.getNearGateFlightNum()+"\n"+
                "近机位旅客数量: "+solution.getNearGatePeopleNum()+"\n"+
                "最终得分为: "+getScore(solution, totalFlights, totalPeople)+"\n";
    }

}
